home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / zcpp_jae.zip / DEFMACIO.H < prev    next >
C/C++ Source or Header  |  1991-04-26  |  5KB  |  170 lines

  1. /*
  2.  
  3.  
  4.  Copyright (C) 1990 Texas Instruments Incorporated.
  5.  
  6.  Permission is granted to any individual or institution to use, copy, modify,
  7.  and distribute this software, provided that this complete copyright and
  8.  permission notice is maintained, intact, in all copies and supporting
  9.  documentation.
  10.  
  11.  Texas Instruments Incorporated provides this software "as is" without
  12.  express or implied warranty.
  13.  
  14.  
  15.  *  
  16.  * I/O support for internal defmacros
  17.  *   Defmacros which execute in their own process use stdin and stdout.
  18.  *   Defmacros which execute as cpp functions use these routines instead.
  19.  *
  20.  * Edit history
  21.  * Created: LGO 30-Mar-89 -- Initial design and implementation.
  22.  *
  23.  */
  24.  
  25. #include <ctype.h>
  26. #include <stdio.h>
  27.  
  28. #define EOS 0
  29. #ifndef TRUE
  30. #define TRUE  1
  31. #define FALSE 0
  32. #endif
  33.  
  34. typedef int Boolean;
  35.  
  36. /************************************************************/
  37.  
  38. /*  I moved these definitions in here from hash.c because the SAS C
  39.  *  compiler (MVS) complains about not knowing about type Hash_Table
  40.  *  in declaration    extern struct Hash_Table* init_Hash_Table(); 
  41.  *  This looks like a bug their compiler ... DKM
  42.  */
  43.  
  44. #define BUCKET_SIZE 8
  45.  
  46. static int hash_primes[] = {3, 7, 13, 19, 29, 41, 53, 67, 83, 97, 113, 137,
  47.                 163, 191, 223, 263, 307, 349, 401, 461, 521, 587,
  48.                 653, 719, 773, 839, 911, 983, 1049, 1123, 1201,
  49.                 1279, 1367, 1459, 1549, 1657, 1759, 1861, 1973,
  50.                 2081, 2179, 2281, 2383, 2503, 2617, 2729, 2843,
  51.                 2963, 3089, 3203, 3323, 3449, 3571, 3697, 3833,
  52.                 3967, 4099, 4241, 4391, 4549, 4703, 4861, 5011,
  53.                 5171, 5333, 5483, 5669, 5839, 6029, 6197, 6361,
  54.                   6547, 6761, 6961, 7177, 7393, 7517, 7727, 7951,
  55.                 8101, 8209, 16411, 32771, 65537, 131301, 262147,
  56.                 524287};
  57.  
  58. struct hash_pair {
  59.   char* key;
  60.   void* value;
  61. };
  62.  
  63. struct bucket {
  64.   struct hash_pair data[BUCKET_SIZE];
  65. };
  66.  
  67. struct Hash_Table {
  68.   struct bucket* table;
  69.   unsigned char* items_in_buckets;
  70.   int entry_count;            
  71.   int bucket_index;            
  72.   int current_bucket;
  73.   int current_index;
  74. };
  75.  
  76. /**************************************************************/
  77.  
  78. #if defined (DOS) || defined (MSDOS)
  79. extern void free (void *);
  80. #endif
  81.  
  82. extern char* strcpy(/* char*, char* */);
  83. extern char* strcat(/* char*, char* */);
  84. extern char* getmem(/* int byte_count */);
  85. extern char* savestring(/* char* */);
  86. extern cerror(/* char* format_string, char* string_arg */);
  87.  
  88. extern struct Hash_Table* init_Hash_Table();
  89. extern void* get_hash(/* Hash_Table, key */);
  90. extern Boolean put_hash(/* Hash_Table, key, value */);
  91. extern void* next_hash(/* Hash_Table, firstp */);
  92.  
  93. extern char* lookup_symbol(/* char* pkgname, char* symname */);
  94.  
  95. extern void new_defmacro();          /* Define a new defmacro */
  96.  
  97. /*
  98.  * The FILEINFO structure stores information about open files
  99.  * and macros being expanded.
  100.  */
  101. /* WARNING: This structure is duplicated in cpp.h */
  102. typedef struct fileinfo {
  103.     char        *bptr;        /* Buffer pointer    */
  104.     int        line;        /* for include or macro    */
  105.     FILE        *fp;        /* File if non-null    */
  106.     struct fileinfo    *parent;    /* Link to includer    */
  107.     char        *filename;    /* File/macro name    */
  108.     char        *progname;    /* From #line statement    */
  109.     unsigned int    unrecur;    /* For macro recursion    */
  110.     char*        buffer;     /* current input line    */
  111. } FILEINFO;
  112.  
  113. extern FILEINFO *MacInFile, *MacOutFile;
  114. extern char* MacOutEnd;
  115. extern void NextMacOutString(); /* takes 1 char* parameter */
  116. extern char NextMacInChar();
  117. extern void NextMacOutBuffer();
  118. extern void set_inbuffer(/* char* instring */);
  119.  
  120. /* get the next input character */
  121. #undef getchar
  122. #define getchar() (*MacInFile->bptr ? *MacInFile->bptr++ : NextMacInChar())
  123.  
  124. /* unget the last character */
  125. #undef unget
  126. #define unget() (MacInFile->bptr--)
  127.  
  128. /* put the next character to output */
  129. #undef putchar
  130. #define putchar(c) \
  131.   {if (MacOutFile->bptr > MacOutEnd) NextMacOutBuffer(); \
  132.   *MacOutFile->bptr++ = c;}
  133.  
  134. #define puts(s) NextMacOutString(s)
  135.  
  136. extern char  skip_blanks();
  137. extern char  skip_line();
  138. extern char* copytoken(/* char* */);
  139. extern void scan_start();
  140. extern char* scan_next(/* char delim */);
  141. extern char* scan_list(/* char delim */);
  142. extern char* scan_token(/* char* delims */);
  143.  
  144. extern void put_string(/* char* */);
  145.  
  146. extern char* c_upcase(/* char* */);
  147. extern char* c_downcase(/* char* */);
  148. extern char* c_capitalize(/* char* */);
  149. extern char* c_trim_all (/* char*, char* */);
  150.  
  151. typedef struct String {
  152.   char* buff;
  153.   char* buffp;
  154.   char* buffend;
  155. }* STRING;
  156.  
  157. STRING make_STRING(/* int size */);
  158. void destroy_STRING(/* STRING string */);
  159. void grow_STRING(/* STRING string, unsigned int len */);
  160. void append_STRING(/* STRING string, char* chars */);
  161. char append_blanks(/* STRING string */);
  162.  
  163. #define append_char(string, c) \
  164.   { if(string->buffp>=string->buffend) grow_STRING(string,(unsigned int)0); \
  165.     *string->buffp++ = (c); }
  166.  
  167. extern STRING work_string;        /* string buffer for utilities */
  168. extern int current_line;        /* line at start of defmacro */
  169. extern char current_file[];        /* file at start of defmacro */
  170.